package com.ynjt.client;


import com.ynjt.model.Message;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

@ChannelHandler.Sharable
public class ChatClientHandler extends SimpleChannelInboundHandler<Message>  {

    private final ChatClient client;

    /**
     * Creates a client-side handler.
     */
    public ChatClientHandler(ChatClient client) {
        this.client = client;
    }


    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, Message message) throws Exception {
        System.out.printf("ChatClientHandler  channelRead");
        client.getOutputText().append(message.getName() + " : " + message.getContent()+"\n");
    }

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
        System.out.println("client channelReadComplete");
    }


}
